package com.fita.admin.entity.search.agent;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;
import com.fita.entity.agent.AgentApplyStatus;
import com.fita.entity.agent.AgentType;

import java.util.Map;

/**
 * 
 * @author 宋剑宏
 *
 */
public class AgentAuditSearch implements QueryBuilder {

	/** email */
	private String email;



	/** 姓名 */
	private String name;
	
	/**
	 * 状态
	 */
	private AgentApplyStatus status;
	
	
	/** 关联分区 */
	private Long districtId;

	/** 代理类型 */
	private AgentType type;

	/** 手机 */
	private String mobile;
	
	/** * 所属销售*/
	private Long principalId;

	/** 公司名称 */
	private String companyName;

	private QueryFilter filter;

	private QueryOrder order;

	/**
	 * The default constructor
	 */
	public AgentAuditSearch() {
		order = new QueryOrder();
	}
    
	
	/**
	 *  
	 * @param districtId
	 * @return
	 */
	public AgentAuditSearch setDistrictID(Long districtId) {
		this.districtId = districtId;
		return this;
			
		}
	
	public AgentAuditSearch setPrincipalIds(Long principalId) {
		this.principalId = principalId;
		return this;
		}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
	 */
	public QueryFilter getPreparedFilter(boolean refresh) {
		if (filter == null || refresh) {
			filter = new QueryFilter().addLike("email", email)
					.addLike("name", name)
					.addEquals("principal.id", principalId)
					.addEquals("district.id", districtId)
					.addEquals("status", status)
					.addEquals("type", type)
					.addEquals("mobile", mobile)
					.addLike("companyName", companyName);

		}
		return filter;
	}
	
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
	 */
	public QueryOrder getOrder() {
		return order;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
	 */
	public String buildSentenceTemplate() {
		String sentence = "FROM AgentApply WHERE disabled = false" + getPreparedFilter(false).clauseSentence()
				+ order.sentence();
		return sentence;
	}
	
	
	
	/*
	 * 
	 */
	public String buildSentenceTemplates() {
		String sentence = "FROM AgentApply WHERE 1=1" + getPreparedFilter(false).clauseSentence()
				+ order.sentence();
		return sentence;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
	 */
	public Map<String, Object> buildParameters() {
		return getPreparedFilter(false).parameters();
	}


	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}


	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}


	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}


	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}


	/**
	 * @return the status
	 */
	public AgentApplyStatus getStatus() {
		return status;
	}


	/**
	 * @param status the status to set
	 */
	public void setStatus(AgentApplyStatus status) {
		this.status = status;
	}


	/**
	 * @return the districtId
	 */
	public Long getDistrictId() {
		return districtId;
	}


	/**
	 * @param districtId the districtId to set
	 */
	public void setDistrictId(Long districtId) {
		this.districtId = districtId;
	}


	/**
	 * @return the type
	 */
	public AgentType getType() {
		return type;
	}


	/**
	 * @param type the type to set
	 */
	public void setType(AgentType type) {
		this.type = type;
	}


	/**
	 * @return the mobile
	 */
	public String getMobile() {
		return mobile;
	}


	/**
	 * @param mobile the mobile to set
	 */
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}


	/**
	 * @return the principalId
	 */
	public Long getPrincipalId() {
		return principalId;
	}


	/**
	 * @param principalId the principalId to set
	 */
	public void setPrincipalId(Long principalId) {
		this.principalId = principalId;
	}


	/**
	 * @return the companyName
	 */
	public String getCompanyName() {
		return companyName;
	}


	/**
	 * @param companyName the companyName to set
	 */
	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}


	/**
	 * @return the filter
	 */
	public QueryFilter getFilter() {
		return filter;
	}

}
